/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mxgraph.examples.swing.editor;

import java.awt.HeadlessException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.JOptionPane;

import com.mxgraph.examples.swing.GraphEditor;
import com.mxgraph.view.mxGraph;
import java.sql.Statement;

/**
 *
 * @author User
 */
public class PropertyForm extends javax.swing.JFrame {

    String deviceType;
    //String name;
    mxGraph graph;
    double dx, dy;
    private String ipAddress;

    /**
     * Creates new form configureDeviceProperty
     */
    public PropertyForm(String typeOfDevice, mxGraph graph, double dx, double dy, String ip) {
        this.deviceType = typeOfDevice;
        this.graph = graph;
        this.dx = dx;
        this.dy = dy;
        this.ipAddress = ip;

        initComponents();
    }

    public PropertyForm() throws HeadlessException {
        super();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLabelType = new javax.swing.JLabel();
        jLabelNameDevice = new javax.swing.JLabel();
        jTextFieldName = new javax.swing.JTextField();
        jTextFieldLocation = new javax.swing.JTextField();
        jTextFieldContact = new javax.swing.JTextField();
        jTextFieldMac = new javax.swing.JTextField();
        jTextFieldIP = new javax.swing.JTextField();
        jLabelLocation = new javax.swing.JLabel();
        jLabelContact = new javax.swing.JLabel();
        jLabelIPs = new javax.swing.JLabel();
        jLabelMac = new javax.swing.JLabel();
        jTextFieldType = new javax.swing.JTextField();
        jButtonSave = new javax.swing.JButton();
        jButtonCancel = new javax.swing.JButton();
        jLabelServerOpenPort = new javax.swing.JLabel();
        jTextServerOpenPort = new javax.swing.JTextField();
        jLabelSNMPVersion = new javax.swing.JLabel();
        jTextSNMPVersion = new javax.swing.JTextField();
        jLabelSNMPCommunityRead = new javax.swing.JLabel();
        jTextSNMPCommunityRead = new javax.swing.JTextField();
        jLabelDescription = new javax.swing.JLabel();
        jTextDescription = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Configure Device Property");
        setAlwaysOnTop(true);
        setResizable(false);

        jLabelType.setText("Device Type:");
        jTextFieldType.setText(deviceType);
        jTextFieldType.setEnabled(false);

        jLabelNameDevice.setText("System Name :");
        /*
         jTextFieldName.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
         jTextFieldNameActionPerformed(evt);
         }
         });

         jTextFieldLocation.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
         jTextFieldLocationActionPerformed(evt);
         }
         });

         jTextFieldContact.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
         jTextFieldContactActionPerformed(evt);
         }
         });

         jTextFieldMac.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
         jTextFieldMacActionPerformed(evt);
         }
         });

         jTextFieldIP.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
         jTextFieldIPActionPerformed(evt);
               
         }
         });
         */
        jLabelLocation.setText("System Location:");

        jLabelContact.setText("UID of Contact Person:");
        jLabelSNMPVersion.setText("SNMP Version(e.g. 1, 2c, 3):");
        jLabelSNMPCommunityRead.setText("SNMP Community String for RO:");
        jLabelDescription.setText("System Description:");
        if (deviceType.equals("Switch") || deviceType.equals("Server")) {
            jLabelIPs.setText("IP*:");

        } else if (deviceType.equals("Router") || deviceType.equals("Firewall")) {
            jLabelIPs.setText("Reachable IPs of Device(e.g. 1.1.1.1,1.2.3.4):");
        } else {
            jLabelIPs.setText("IP:");
        }
        if (deviceType.equals("Workplace")) {
            jLabelMac.setText("MAC*:");
        } else {
            jLabelMac.setText("MAC:");
        }
        if (deviceType.equals("Server")) {
            jLabelServerOpenPort.setText("<html>Porvide Port Number <br>of the Server(e.g. 22,80,8080).*:");

        }
        jTextFieldType.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldTypeActionPerformed(evt);

            }
        });

        String save;
        if (deviceType.equals("Switch")) {
            save = "Proceed";
        } else {
            save = "Save";
        }
        jButtonSave.setText(save);
        jButtonSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                try {
                    Object parent = graph.getDefaultParent();
                    System.out.print(deviceType);
                    //jTextFieldIP.getText().
                    //if((deviceType.equals("Switch")||(deviceType.equals("User")||(deviceType.equals("Router")||(deviceType.equals("Cloud")&&(jTextFieldIP.getText().length()==0)){
                    Pattern ipAddressPattern = Pattern.compile("^(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}$");
                    if (deviceType.equals("Switch")) {
                        if (jTextFieldIP.getText().length() == 0) {

                            JOptionPane.showMessageDialog(null, "ENTER IP");
                        } else {


                            String ipAddr = jTextFieldIP.getText();
                            Matcher matchIPAddressPattern = ipAddressPattern.matcher(ipAddr);
                            if (!matchIPAddressPattern.find()) {
                                JOptionPane.showMessageDialog(null, "ENTER Valid IP");
                            } else {
                                Deviceform ipInformationForm = new Deviceform(jTextFieldContact.getText(),jTextFieldLocation.getText(),jTextDescription.getText(),jTextFieldIP.getText(), jTextFieldName.getText(), graph, dx, dy);
                                ipInformationForm.setVisible(true);
                                ipAddress = jTextFieldIP.getText();
                                GraphEditor ge = new GraphEditor(null, ipAddr);
                                dispose();
                            }

                            //this.ip=jTextFieldIP;
                            //dispose(); 
                        }
                    } else if ((deviceType.equals("Printer") && (jTextFieldIP.getText().length() == 0))) {
                        JOptionPane.showMessageDialog(null, "ENTER IP");

                    } else if ((deviceType.equals("Server")) && (jTextFieldIP.getText().length() == 0) && (jTextServerOpenPort.getText().length() == 0)) {
                        JOptionPane.showMessageDialog(null, "ENTER IP AND PORT ADDRESS");
                    } else if ((deviceType.equals("Workplace") && (jTextFieldMac.getText().length() == 0))) {
                        JOptionPane.showMessageDialog(null, "ENTER MAC");
                    } else {

                        //Pattern ptn = Pattern.compile("(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)");
                        // Pattern ptn = Pattern.compile("^(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}$");
                        String ipAddr = jTextFieldIP.getText();
                        Matcher matchIPAddressPattern = ipAddressPattern.matcher(ipAddr);
                        Pattern macAddressPattern = Pattern.compile("^([0-9A-Fa-f]{2}[:]){5}[0-9A-Fa-f]{2}$");
                        String macAddr = jTextFieldMac.getText();
                        Matcher matchMACAddressPattern = macAddressPattern.matcher(macAddr);

                        /*if(!mtch1.find()){
                         JOptionPane.showMessageDialog(null, "ENTER Valid MAC");
                         } */
                        /* if(!mtch.find()){
                         JOptionPane.showMessageDialog(null, "ENTER Valid IP");*/
                        if (deviceType.equals("Router")) {
                               if (jTextFieldIP.getText().length() == 0) {

                            JOptionPane.showMessageDialog(null, "ENTER IP");
                        } else {
                            String sqlfind = "SHOW TABLES LIKE 'packetfence_router_info'";
                            Statement stmt = DatabaseConnectivity.generateStatement();
                            int norow = stmt.executeUpdate(sqlfind);
                            stmt.close();
                            //dispose();


//            	 stmt.executeUpdate(sqlfind);
                            if (norow == 0) {
                                //norow=0 represents the table is not available in databse otherwise available if norow=-1

                                System.out.println(norow + "NOROW");
                                // packetfencenew1_switch_info is a new database

                                String sqlcreate;
                                sqlcreate = "CREATE TABLE packetfence_router_info(IPs VARCHAR(200) NOT NULL ,"
                                        + "Type VARCHAR (20) ,sysName VARCHAR(200),contactPersonUID VARCHAR(200),"
                                        + "sysLocation VARCHAR(1000),sysDescryption VARCHAR(2000),SNMPVersion VARCHAR (20) ,"
                                        + "SNMPCommunityRead VARCHAR (20) ,PRIMARY KEY (IPs))";

                                String sql;
                                sql = "INSERT INTO `packetfence_router_info`(`ips`, `type`, `sysname`, "
                                        + "`contactpersonuid`,`syslocation`,`sysdescryption`,`snmpversion`  ,"
                                        + "`snmpcommunityread' ) VALUES "
                                        + "('" + jTextFieldIP.getText() + "','" + deviceType + "','" 
                                        + jTextFieldName.getText() + "','" + jTextFieldContact.getText() + "','" 
                                        + jTextFieldLocation.getText() + "','" + jTextDescription.getText() + "','" 
                                        + jTextSNMPVersion.getText() + "','" + jTextSNMPCommunityRead.getText() + "')";

                                Statement sqlStatement = DatabaseConnectivity.generateStatement();
                                // ArrayListofVisibleItem.arrlist.add(ip);
                                sqlStatement.executeUpdate(sqlcreate);
                                sqlStatement.close();
                                Statement sqlStatement1 = DatabaseConnectivity.generateStatement();
                                sqlStatement1.executeUpdate(sql);
                                sqlStatement1.close();
                                dispose();


                            } else {
                                String sql;
                                sql = "INSERT INTO `packetfence_router_info`(`ips`, `type`, `sysname`, `contactpersonuid`,"
                                        + "`syslocation`,`sysdescryption`,`snmpversion`  ,`snmpcommunityread` ) VALUES "
                                        + "('" + jTextFieldIP.getText() + "','" + deviceType + "','" 
                                        + jTextFieldName.getText() + "','" + jTextFieldContact.getText() + "','" 
                                        + jTextFieldLocation.getText() + "','" + jTextDescription.getText() + "','" 
                                        + jTextSNMPVersion.getText() + "','" + jTextSNMPCommunityRead.getText() + "')";

                                //DatabaseConnectivity connectivity=new DatabaseConnectivity();

                                Statement sqlStatement = DatabaseConnectivity.generateStatement();
                                sqlStatement.executeUpdate(sql);
                                sqlStatement.close();
                                dispose();
                            }
                            String[] firstIP = jTextFieldIP.getText().split(",");
                            graph.insertVertex(parent, "Router_" + jTextFieldIP.getText(), firstIP[0], dx, dy, 30, 30,
                                    "image;image=/com/mxgraph/examples/swing/images/RouterGreen.png");
                        } }

                        //else if (deviceType.equals("Cloud")) {
                        //   graph.insertVertex(parent, "Cloud_" + jTextFieldIP.getText(), jTextFieldIP.getText(), 20, 20, 30, 30,
                        //         "image;image=/com/mxgraph/examples/swing/images/CloudIcon.png");
                        //} 
                        
                        else if (deviceType.equals("Firewall")) {
                             if (jTextFieldIP.getText().length() == 0) {

                            JOptionPane.showMessageDialog(null, "ENTER IP");
                        } else {
                          //  if (!matchIPAddressPattern.find()) {
                           //     JOptionPane.showMessageDialog(null, "ENTER Valid IP");
                           // } else {
                            String sqlfind = "SHOW TABLES LIKE 'packetfence_firewall_info'";
                            Statement stmt = DatabaseConnectivity.generateStatement();
                            int norow = stmt.executeUpdate(sqlfind);
                            stmt.close();
                            //dispose();


//            	 stmt.executeUpdate(sqlfind);
                            if (norow == 0) {
                                //norow=0 represents the table is not available in databse otherwise available if norow=-1

                                System.out.println(norow + "NOROW");
                                // packetfencenew1_switch_info is a new database

                                String sqlcreate;
                                sqlcreate = "CREATE TABLE packetfence_firewall_info(IPs VARCHAR(200) NOT NULL ,"
                                        + "Type VARCHAR (20) ,sysName VARCHAR(200),contactPersonUID VARCHAR(200),"
                                        + "sysLocation VARCHAR(1000),sysDescryption VARCHAR(2000),SNMPVersion VARCHAR (20) ,"
                                        + "SNMPCommunityRead VARCHAR (20) ,PRIMARY KEY (IPs))";

                                String sql;
                                sql = "INSERT INTO `packetfence_firewall_info`(`ips`, `type`, `sysname`, "
                                        + "`contactpersonuid`,`syslocation`,`sysdescryption`,`snmpversion`  ,"
                                        + "`snmpcommunityread` ) VALUES "
                                        + "('" + jTextFieldIP.getText() + "','" + deviceType + "','" + jTextFieldName.getText() + "','" 
                                        + jTextFieldContact.getText() + "','" + jTextFieldLocation.getText() + "','" 
                                        + jTextDescription.getText() + "','" + jTextSNMPVersion.getText() + "','" 
                                        + jTextSNMPCommunityRead.getText() + "')";

                                Statement sqlStatement = DatabaseConnectivity.generateStatement();
                                // ArrayListofVisibleItem.arrlist.add(ip);
                                sqlStatement.executeUpdate(sqlcreate);
                                sqlStatement.close();
                                Statement sqlStatement1 = DatabaseConnectivity.generateStatement();
                                sqlStatement1.executeUpdate(sql);
                                sqlStatement1.close();
                                dispose();


                            } else {
                                String sql;
                                sql = "INSERT INTO `packetfence_firewall_info`(`ips`, `type`, `sysname`, `contactpersonuid`,"
                                        + "`syslocation`,`sysdescryption`,`snmpversion`  ,`snmpcommunityread` ) VALUES "
                                        + "('" + jTextFieldIP.getText() + "','" + deviceType + "','" + jTextFieldName.getText() + "','" + jTextFieldContact.getText() + "','" + jTextFieldLocation.getText() + "','" 
                                        + jTextDescription.getText() + "','" + jTextSNMPVersion.getText() + "','" 
                                        + jTextSNMPCommunityRead.getText() + "')";

                                //DatabaseConnectivity connectivity=new DatabaseConnectivity();

                                Statement sqlStatement = DatabaseConnectivity.generateStatement();
                                sqlStatement.executeUpdate(sql);
                                sqlStatement.close();
                                dispose();
                            }

                            
                             String[] firstIP = jTextFieldIP.getText().split(",");
                                graph.insertVertex(parent, "Firewall_" + jTextFieldIP.getText(), firstIP[0], dx, dy, 30, 30,
                                        "roundImage;image=/com/mxgraph/examples/swing/images/FirewallIcon.png");
                           // }
                        }}

                        if (deviceType.equals("Server") && !(jTextFieldIP.getText().isEmpty())) {
                             if (jTextFieldIP.getText().length() == 0) {

                            JOptionPane.showMessageDialog(null, "ENTER IP");
                        } else {
                            if (!matchIPAddressPattern.find()) {
                                JOptionPane.showMessageDialog(null, "ENTER Valid IP");
                            } else {
                            String sqlfind = "SHOW TABLES LIKE 'packetfence_server_info'";
                            Statement stmt = DatabaseConnectivity.generateStatement();
                            int norow = stmt.executeUpdate(sqlfind);
                            stmt.close();
                            //dispose();


//            	 stmt.executeUpdate(sqlfind);
                            if (norow == 0) {
                                //norow=0 represents the table is not available in databse otherwise available if norow=-1

                                System.out.println(norow + "NOROW");
                                // packetfencenew1_switch_info is a new database

                                String sqlcreate;
                                sqlcreate = "CREATE TABLE packetfence_server_info(IP VARCHAR(200) NOT NULL ,Type VARCHAR (20) "
                                        + ",sysName VARCHAR(200),contactPersonUID VARCHAR(200),sysLocation VARCHAR(1000)"
                                        + ",sysDescryption VARCHAR(2000),MAC VARCHAR (80) ,PortNumber VARCHAR (100) ,PRIMARY KEY (IP))";

                                String sql;
                                sql = "INSERT INTO `packetfence_server_info`(`ip`, `type`, `sysname`, `contactpersonuid`,"
                                        + "`syslocation`,`sysdescryption`,`mac`,  `portnumber`   ) VALUES "
                                        + "('" + jTextFieldIP.getText() + "','" + deviceType + "','" 
                                        + jTextFieldName.getText() + "','" + jTextFieldContact.getText() + "','" 
                                        + jTextFieldLocation.getText() + "','"+ jTextDescription.getText() + "','"
                                        + jTextFieldMac.getText() + "','"  + jTextServerOpenPort.getText() +  "')";

                                Statement sqlStatement = DatabaseConnectivity.generateStatement();
                                // ArrayListofVisibleItem.arrlist.add(ip);
                                sqlStatement.executeUpdate(sqlcreate);
                                sqlStatement.close();
                                Statement sqlStatement1 = DatabaseConnectivity.generateStatement();
                                sqlStatement1.executeUpdate(sql);
                                sqlStatement1.close();
                                dispose();


                            } else {
                                String sql;
                                sql = "INSERT INTO `packetfence_server_info`(`ip`, `type`, `sysname`, `contactpersonuid`,"
                                        + "`syslocation`,`sysdescryption`,`mac`,  `portnumber`   ) VALUES "
                                        + "('" + jTextFieldIP.getText() + "','" + deviceType + "','" 
                                        + jTextFieldName.getText() + "','" + jTextFieldContact.getText() + "','" 
                                        + jTextFieldLocation.getText() + "','"+ jTextDescription.getText() + "','"
                                        + jTextFieldMac.getText() + "','"  + jTextServerOpenPort.getText() +  "')";

                                //DatabaseConnectivity connectivity=new DatabaseConnectivity();

                                Statement sqlStatement = DatabaseConnectivity.generateStatement();
                                sqlStatement.executeUpdate(sql);
                                sqlStatement.close();
                                dispose();
                            }


                                graph.insertVertex(parent, "Server_" + jTextFieldIP.getText(), jTextFieldIP.getText(), dx, dy, 50, 50,
                                        "image;image=/com/mxgraph/examples/swing/images/ServerGreen.png");
                            }
                        }}

                  /*      if (deviceType.equals("Switch") && !(jTextFieldIP.getText().isEmpty())) {
                            if (!matchIPAddressPattern.find()) {
                                JOptionPane.showMessageDialog(null, "ENTER Valid IP");
                            } else {
                                //System.out.print("Inside Switch");
                                graph.insertVertex(parent, "Switch_" + jTextFieldIP.getText(), jTextFieldIP.getText(), dx, dy, 30, 30,
                                        "image;image=/com/mxgraph/examples/swing/images/SwitchIcon.png");

                                dispose();
                            }
                        }*/

                        if (deviceType.equals("Workplace") && !(jTextFieldMac.getText().isEmpty())) {
                            if (!matchMACAddressPattern.find()) {
                                JOptionPane.showMessageDialog(null, "ENTER Valid MAC");
                            } else {
                            String sqlfind = "SHOW TABLES LIKE 'packetfence_workplace_info'";
                            Statement stmt = DatabaseConnectivity.generateStatement();
                            int norow = stmt.executeUpdate(sqlfind);
                            stmt.close();
                            //dispose();


//            	 stmt.executeUpdate(sqlfind);
                            if (norow == 0) {
                                //norow=0 represents the table is not available in databse otherwise available if norow=-1

                                System.out.println(norow + "NOROW");
                                // packetfencenew1_switch_info is a new database

                                String sqlcreate;
                                sqlcreate = "CREATE TABLE packetfence_workplace_info(IP VARCHAR(200) NOT NULL ,"
                                        + "Type VARCHAR (20) ,sysName VARCHAR(200),contactPersonUID VARCHAR(200),"
                                        + "sysLocation VARCHAR(1000),MAC VARCHAR (80) ,"
                                        + "sysDescryption VARCHAR(2000),SNMPVersion VARCHAR (20) ,"
                                        + "SNMPCommunityRead VARCHAR (20) ,"
                                        + "PRIMARY KEY (IP))";

                                String sql;
                                sql = "INSERT INTO `packetfence_workplace_info`(`ip`, `type`, `sysname`, `contactpersonuid`,"
                                        + "`syslocation`,`mac`,`sysdescryption`,`snmpversion`  ,"
                                        + "`snmpcommunityread`    ) VALUES "
                                        + "('" + jTextFieldIP.getText() + "','" + deviceType + "','" + jTextFieldName.getText() + "','" 
                                        + jTextFieldContact.getText() + "','" + jTextFieldLocation.getText() + "','" 
                                         + jTextFieldMac.getText() + "','"+ jTextDescription.getText() + "','" 
                                        + jTextSNMPVersion.getText() + "','" + jTextSNMPCommunityRead.getText() + "')";

                                Statement sqlStatement = DatabaseConnectivity.generateStatement();
                                // ArrayListofVisibleItem.arrlist.add(ip);
                                sqlStatement.executeUpdate(sqlcreate);
                                sqlStatement.close();
                                Statement sqlStatement1 = DatabaseConnectivity.generateStatement();
                                sqlStatement1.executeUpdate(sql);
                                sqlStatement1.close();
                                dispose();


                            } else {
                                String sql;
                                sql = "INSERT INTO `packetfence_workplace_info`(`ip`, `type`, `sysname`, `contactpersonuid`,"
                                        + "`syslocation`,`mac`,`sysdescryption`,`snmpversion`  ,"
                                        + "`snmpcommunityread`    ) VALUES "
                                        + "('" + jTextFieldIP.getText() + "','" + deviceType + "','" + jTextFieldName.getText() + "','" 
                                        + jTextFieldContact.getText() + "','" + jTextFieldLocation.getText() + "','" 
                                         + jTextFieldMac.getText() + "','"+ jTextDescription.getText() + "','" 
                                        + jTextSNMPVersion.getText() + "','" + jTextSNMPCommunityRead.getText() + "')";
                                //DatabaseConnectivity connectivity=new DatabaseConnectivity();

                                Statement sqlStatement = DatabaseConnectivity.generateStatement();
                                sqlStatement.executeUpdate(sql);
                                sqlStatement.close();
                                dispose();
                            }

                                graph.insertVertex(parent, "Worksplace_" + jTextFieldMac.getText(), jTextFieldMac.getText(), dx, dy, 30, 30,
                                        "image;image=/com/mxgraph/examples/swing/images/workplace.png");

                               // dispose();
                            }
                        }
                        if (deviceType.equals("Printer") && !(jTextFieldIP.getText().isEmpty())) {
                            if (!matchIPAddressPattern.find()) {
                                JOptionPane.showMessageDialog(null, "ENTER Valid IP");
                            } else {
                            String sqlfind = "SHOW TABLES LIKE 'packetfence_printer_info'";
                            Statement stmt = DatabaseConnectivity.generateStatement();
                            int norow = stmt.executeUpdate(sqlfind);
                            stmt.close();
                            //dispose();


//            	 stmt.executeUpdate(sqlfind);
                            if (norow == 0) {
                                //norow=0 represents the table is not available in databse otherwise available if norow=-1

                                System.out.println(norow + "NOROW");
                                // packetfencenew1_switch_info is a new database

                                String sqlcreate;
                                sqlcreate = "CREATE TABLE packetfence_printer_info(IP VARCHAR(200) NOT NULL ,"
                                        + "Type VARCHAR (20) ,sysName VARCHAR(200),contactPersonUID VARCHAR(200),"
                                        + "sysLocation VARCHAR(1000),MAC VARCHAR (80) ,"
                                        + "sysDescryption VARCHAR(2000),SNMPVersion VARCHAR (20) ,"
                                        + "SNMPCommunityRead VARCHAR (20) ,"
                                        + "PRIMARY KEY (IP))";

                                String sql;
                                sql = "INSERT INTO `packetfence_printer_info`(`ip`, `type`, `sysname`, `contactpersonuid`,"
                                        + "`syslocation`,`mac`,`sysdescryption`,`snmpversion`  ,"
                                        + "`snmpcommunityread`   ) VALUES "
                                        + "('" + jTextFieldIP.getText() + "','" + deviceType + "','" + jTextFieldName.getText() + "','" 
                                        + jTextFieldContact.getText() + "','" + jTextFieldLocation.getText() + "','" 
                                        + jTextFieldMac.getText() + "','"+ jTextDescription.getText() + "','" + jTextSNMPVersion.getText() + "','" 
                                        + jTextSNMPCommunityRead.getText() + "')";

                                Statement sqlStatement = DatabaseConnectivity.generateStatement();
                                // ArrayListofVisibleItem.arrlist.add(ip);
                                sqlStatement.executeUpdate(sqlcreate);
                                sqlStatement.close();
                                Statement sqlStatement1 = DatabaseConnectivity.generateStatement();
                                sqlStatement1.executeUpdate(sql);
                                sqlStatement1.close();
                                dispose();


                            } else {
                                String sql;
                                sql = "INSERT INTO `packetfence_printer_info`(`ip`, `type`, `sysname`, `contactpersonuid`,"
                                        + "`syslocation`,`mac`,`sysdescryption`,`snmpversion`  ,"
                                        + "`snmpcommunityread`   ) VALUES "
                                        + "('" + jTextFieldIP.getText() + "','" + deviceType + "','" + jTextFieldName.getText() + "','" 
                                        + jTextFieldContact.getText() + "','" + jTextFieldLocation.getText() + "','" 
                                        + jTextFieldMac.getText() + "','"+ jTextDescription.getText() + "','" + jTextSNMPVersion.getText() + "','" 
                                        + jTextSNMPCommunityRead.getText() + "')";

                                //DatabaseConnectivity connectivity=new DatabaseConnectivity();

                                Statement sqlStatement = DatabaseConnectivity.generateStatement();
                                sqlStatement.executeUpdate(sql);
                                sqlStatement.close();
                                dispose();
                            }

                                System.out.print("Inside Printer");
                                graph.insertVertex(parent, "Printer_" + jTextFieldIP.getText(), jTextFieldIP.getText(), dx, dy, 30, 30,
                                        "image;image=/com/mxgraph/examples/swing/images/PrinterGreen.png");

                                dispose();
                            }
                        }

                        //graph.insertVertex(arg0, arg1, arg2, arg3, arg4, arg5, arg6)
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        jButtonCancel.setText("CANCEL");
        jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelActionPerformed(evt);
                dispose();
            }
        });
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        if (deviceType.equals("Server")) {
            layout.setHorizontalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                    .addContainerGap(111, Short.MAX_VALUE)
                    .addComponent(jButtonSave)
                    .addGap(62, 62, 62)
                    .addComponent(jButtonCancel)
                    .addGap(47, 47, 47))
                    .addGroup(layout.createSequentialGroup()
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelMac)
                    .addComponent(jLabelType)
                    .addComponent(jLabelIPs)
                    ////
                    .addComponent(jLabelServerOpenPort) ////
                    .addComponent(jLabelDescription)
                    )
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextFieldIP, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                    .addComponent(jTextFieldMac)
                    .addComponent(jTextServerOpenPort)))
                    .addGroup(layout.createSequentialGroup()
                    .addGap(62, 62, 62)
                    .addComponent(jTextFieldType))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelContact)
                    // .addComponent(jLabelLocation, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelLocation)
                    .addComponent(jLabelNameDevice))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jTextFieldName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                    .addComponent(jTextFieldContact)
                    .addComponent(jTextFieldLocation)
                    .addComponent(jTextDescription)
                    )))
                    .addGap(20, 20, 20)));
            layout.setVerticalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                    .addGap(37, 37, 37)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelType)
                    .addComponent(jTextFieldType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNameDevice)
                    .addComponent(jTextFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelLocation)
                    .addComponent(jTextFieldLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelContact)
                    .addComponent(jTextFieldContact, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelMac)
                    .addComponent(jTextFieldMac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    ///////////////
                    .addComponent(jLabelIPs)
                    .addComponent(jTextFieldIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    /////////////////
                    //                 if (deviceType.equals("Server")) {
                    .addComponent(jLabelDescription)
                    .addComponent(jTextDescription, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
                    ///////////
                    .addComponent(jLabelServerOpenPort)
                    .addComponent(jTextServerOpenPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    //}
                    .addComponent(jButtonSave)
                    .addComponent(jButtonCancel))
                    .addGap(20, 20, 20)));
        } else if (deviceType.equals("Switch")) {
            layout.setHorizontalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                    .addContainerGap(111, Short.MAX_VALUE)
                    .addComponent(jButtonSave)
                    .addGap(62, 62, 62)
                    .addComponent(jButtonCancel)
                    .addGap(47, 47, 47))
                    .addGroup(layout.createSequentialGroup()
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    //.addComponent(jLabelMac)
                    .addComponent(jLabelType)
                    .addComponent(jLabelIPs)
                    .addComponent(jLabelDescription)
                    )
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextFieldIP, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                    //.addComponent(jTextFieldMac)
                    ))
                    .addGroup(layout.createSequentialGroup()
                    .addGap(62, 62, 62)
                    .addComponent(jTextFieldType)
                    
                    )))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelContact)
                    .addComponent(jLabelLocation)
                    //.addComponent(jLabelLocation, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelNameDevice))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jTextFieldName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                    .addComponent(jTextFieldContact)
                    .addComponent(jTextFieldLocation)
                   .addComponent(jTextDescription)
                    )))
                    .addGap(20, 20, 20)));
            layout.setVerticalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                    .addGap(37, 37, 37)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelType)
                    .addComponent(jTextFieldType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNameDevice)
                    .addComponent(jTextFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelLocation)
                    .addComponent(jTextFieldLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelContact)
                    .addComponent(jTextFieldContact, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   // .addComponent(jLabelMac)
                   // .addComponent(jTextFieldMac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                   // .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                   // .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    ///////////////
                    .addComponent(jLabelIPs)
                    .addComponent(jTextFieldIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    /////////////////
                    .addComponent(jLabelDescription)
                    .addComponent(jTextDescription, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     
                    //////////////////
                    //                 if (deviceType.equals("Server")) {
                    // .addComponent(jLabelServerOpenPort)
                    //  .addComponent(jTextServerOpenPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    //  .addGap(20, 20, 20)

                    // .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    //}
                    .addComponent(jButtonSave)
                    .addComponent(jButtonCancel))
                    .addGap(20, 20, 20)));
        } 
        else if(deviceType.equals("Router")||deviceType.equals("Firewall")){
        layout.setHorizontalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                    .addContainerGap(111, Short.MAX_VALUE)
                    .addComponent(jButtonSave)
                    .addGap(62, 62, 62)
                    .addComponent(jButtonCancel)
                    .addGap(47, 47, 47))
                    .addGroup(layout.createSequentialGroup()
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                   // .addComponent(jLabelMac)
                    .addComponent(jLabelType)
                    .addComponent(jLabelIPs)
                    .addComponent(jLabelSNMPVersion)
                    .addComponent(jLabelSNMPCommunityRead)
                    .addComponent(jLabelDescription))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextFieldIP, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                    //.addComponent(jTextFieldMac)
                ))
                    .addGroup(layout.createSequentialGroup()
                    .addGap(62, 62, 62)
                    .addComponent(jTextFieldType))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelContact)
                    .addComponent(jLabelLocation)
                    //.addComponent(jLabelLocation, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelNameDevice))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jTextFieldName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                    .addComponent(jTextFieldContact)
                    .addComponent(jTextFieldLocation)
                    .addComponent(jTextSNMPVersion)
                    .addComponent(jTextSNMPCommunityRead)
                    .addComponent(jTextDescription))))
                    .addGap(20, 20, 20)));
            layout.setVerticalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                    .addGap(37, 37, 37)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelType)
                    .addComponent(jTextFieldType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNameDevice)
                    .addComponent(jTextFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelLocation)
                    .addComponent(jTextFieldLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelContact)
                    .addComponent(jTextFieldContact, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   //.addComponent(jLabelMac)
                    //.addComponent(jTextFieldMac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                   // .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                   // .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    ///////////////
                    .addComponent(jLabelIPs)
                    .addComponent(jTextFieldIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    /////////////////
                    ///////////////
                    .addComponent(jLabelSNMPVersion)
                    .addComponent(jTextSNMPVersion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    /////////////////
                    ///////////////
                    .addComponent(jLabelSNMPCommunityRead)
                    .addComponent(jTextSNMPCommunityRead, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    /////////////////
                    ///////////////
                    .addComponent(jLabelDescription)
                    .addComponent(jTextDescription, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    /////////////////
                    //                 if (deviceType.equals("Server")) {
                    // .addComponent(jLabelServerOpenPort)
                    //  .addComponent(jTextServerOpenPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    //  .addGap(20, 20, 20)

                    // .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    //}
                    .addComponent(jButtonSave)
                    .addComponent(jButtonCancel))
                    .addGap(20, 20, 20)));}
        else {
            layout.setHorizontalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                    .addContainerGap(111, Short.MAX_VALUE)
                    .addComponent(jButtonSave)
                    .addGap(62, 62, 62)
                    .addComponent(jButtonCancel)
                    .addGap(47, 47, 47))
                    .addGroup(layout.createSequentialGroup()
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelMac)
                    .addComponent(jLabelType)
                    .addComponent(jLabelIPs)
                    .addComponent(jLabelSNMPVersion)
                    .addComponent(jLabelSNMPCommunityRead)
                    .addComponent(jLabelDescription))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextFieldIP, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                    .addComponent(jTextFieldMac)))
                    .addGroup(layout.createSequentialGroup()
                    .addGap(62, 62, 62)
                    .addComponent(jTextFieldType))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelContact)
                    .addComponent(jLabelLocation)
                    //.addComponent(jLabelLocation, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelNameDevice))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jTextFieldName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                    .addComponent(jTextFieldContact)
                    .addComponent(jTextFieldLocation)
                    .addComponent(jTextSNMPVersion)
                    .addComponent(jTextSNMPCommunityRead)
                    .addComponent(jTextDescription))))
                    .addGap(20, 20, 20)));
            layout.setVerticalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                    .addGap(37, 37, 37)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelType)
                    .addComponent(jTextFieldType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNameDevice)
                    .addComponent(jTextFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelLocation)
                    .addComponent(jTextFieldLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelContact)
                    .addComponent(jTextFieldContact, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelMac)
                    .addComponent(jTextFieldMac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    ///////////////
                    .addComponent(jLabelIPs)
                    .addComponent(jTextFieldIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    /////////////////
                    ///////////////
                    .addComponent(jLabelSNMPVersion)
                    .addComponent(jTextSNMPVersion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    /////////////////
                    ///////////////
                    .addComponent(jLabelSNMPCommunityRead)
                    .addComponent(jTextSNMPCommunityRead, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    /////////////////
                    ///////////////
                    .addComponent(jLabelDescription)
                    .addComponent(jTextDescription, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(20, 20, 20)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    /////////////////
                    //                 if (deviceType.equals("Server")) {
                    // .addComponent(jLabelServerOpenPort)
                    //  .addComponent(jTextServerOpenPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    //  .addGap(20, 20, 20)

                    // .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    //}
                    .addComponent(jButtonSave)
                    .addComponent(jButtonCancel))
                    .addGap(20, 20, 20)));
        }
        pack();
    }// </editor-fold>                        

    private void jTextFieldNameActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    private void jTextFieldLocationActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    private void jTextFieldContactActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    private void jTextFieldMacActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    private void jTextFieldIPActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    private void jTextFieldTypeActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButtonCancel;
    private javax.swing.JButton jButtonSave;
    private javax.swing.JLabel jLabelNameDevice;
    private javax.swing.JLabel jLabelLocation;
    private javax.swing.JLabel jLabelContact;
    private javax.swing.JLabel jLabelIPs;
    private javax.swing.JLabel jLabelMac;
    private javax.swing.JLabel jLabelType;
    private javax.swing.JTextField jTextFieldContact;
    private javax.swing.JTextField jTextFieldIP;
    private javax.swing.JTextField jTextFieldLocation;
    private javax.swing.JTextField jTextFieldMac;
    private javax.swing.JTextField jTextFieldName;
    private javax.swing.JTextField jTextFieldType;
    private javax.swing.JLabel jLabelServerOpenPort;
    private javax.swing.JTextField jTextServerOpenPort;
    private javax.swing.JLabel jLabelDescription;
    private javax.swing.JTextField jTextDescription;
    private javax.swing.JLabel jLabelSNMPVersion;
    private javax.swing.JTextField jTextSNMPVersion;
    private javax.swing.JLabel jLabelSNMPCommunityRead;
    private javax.swing.JTextField jTextSNMPCommunityRead;
    // End of variables declaration                   
}
